package com.winner.kafka.producer;

import com.alibaba.fastjson.JSON;
import com.winner.kafka.model.UserLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

@Component
public class UserLogProducer {

    @Autowired
    private KafkaTemplate kafkaTemplate;

    /**
     * 发送数据
     * @param userLog
     */
    public void sendLog(UserLog userLog){
        System.err.println("发送用户日志数据:"+userLog);
        kafkaTemplate.send("user-log", JSON.toJSONString(userLog)); // 使用kafka模板发送信息
    }
}
